package com.stu.utils;

import java.time.LocalDate;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;

/**
 * @author study
 * @version 1.0
 * @date 2021/6/15 16:33
 */
public class DateUtils {
    private static final DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");

    public static LocalDate str2LocalDate(String str) {
        return LocalDate.parse(str, df);
    }

    /**
     * 获取半年时间
     *
     * @return 获取半年时间
     */
    public static LocalDate halfYear() {
        LocalDate halfYear = LocalDate.of(LocalDate.now().getYear(), Month.JUNE, 1);
        return halfYear.with(TemporalAdjusters.lastDayOfMonth());
    }

    /**
     * 结算可转债截止时间
     *
     * @return 如果是9月份以及之后就统计当年年中，否认统计上一年年末
     */
    public static LocalDate caclKzzJZSJ() {
        final LocalDate now = LocalDate.now();
        if (now.getMonth().getValue() > 8) {
            return halfYear();
        }
        return now.minus(1L, ChronoUnit.YEARS).with(TemporalAdjusters.lastDayOfYear());
    }

    public static void main(String[] args) {
        System.out.println(caclKzzJZSJ());
    }
}
